//flutter_animate 库测试
import 'package:flutter/material.dart';
import 'package:flutter_animate/flutter_animate.dart';

class FlutterAnimateTest extends StatefulWidget {
  const FlutterAnimateTest({super.key, required this.title});

  final String title;

  @override
  State<FlutterAnimateTest> createState() => _FlutterAnimateTestState();
}

class _FlutterAnimateTestState extends State<FlutterAnimateTest> with SingleTickerProviderStateMixin {
  bool isOpen = false;
  late AnimationController _controller;

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(vsync: this);
  }

  @override
  void dispose() {
    super.dispose();
  }

  void _incrementCounter() {
    _controller.repeat(reverse: true);
    setState(() {
      isOpen = !isOpen;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: SingleChildScrollView(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          spacing: 10,
          children: <Widget>[
            const Text(
              'flutter_animate 是一个功能强大的动画库，允许你通过简单的链式调用创建复杂的动画效果。它支持多种动画类型，如淡入淡出、缩放、旋转、平移等。' + "\n特点: 持链式调用，代码简洁易读。  提供丰富的预定义动画效果。 支持自定义动画。",
            ),
            Container(
              width: 100,
              height: 100,
              color: Colors.blue,
            )
                .animate(controller: _controller) // 开始动画
                // .fadeIn(duration: 1000.ms) // 淡入效果，持续1秒
                .scale(duration: 1000.ms, begin: Offset(0.9, 0.9), end: Offset(1.1, 1.1)) // 缩放效果，持续1秒
            // .rotate(duration: 1000.ms) // 旋转效果，持续1秒
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}
